/*
 * @Name: 
 * @Author: LiuCaiLin
 * @Date: 2020-04-22 16:22:13
 * @LastEditors: LiuCaiLin
 * @LastEditTime: 2020-04-25 21:11:35
 */

import {
  request
} from '../../utils/request.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: '',
    orderList: '',
    page: 1,
    flag: true,
    pagesize: 10,
    baseUrl: '',
    loadingInfo: '下拉加载更多数据...'

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success(res) {
        that.setData({
          windowHeight: res.windowHeight
        })
      }
    })
    that.setData({
      baseUrl: app.globalData.url
    })
    that.orderList()
  },

  orderList() {
    let that = this
    wx.request({
      url: 'https://www.lythds.com/orderList',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token: wx.getStorageSync('token')
      },
      method: 'POST',
      data: {
        ids: 5,
        pagesize: that.data.pagesize,
        page: that.data.page
      },

      success: res => {
        if (res.data.error_code == 20000) {
          this.setData({
            loadingInfo: '暂无数据...'
          })
        } else {
          let orderList = res.data.data
          let page = ++that.data.page
          if (orderList.length < that.data.pagesize) {
            var flags = false
            this.setData({
              loadingInfo: '暂无更多数据...'
            })
          } else {
            var flags = true
            this.setData({
              loadingInfo: '下拉加载更多数据...'
            })
          }

          let newOrderList = []
          if (that.data.orderList.length > 0) {
            newOrderList = that.data.orderList.concat(orderList)
          } else {
            newOrderList = orderList
          }

          that.setData({
            orderList: newOrderList,
            page,
            flag: flags
          })
        }
      }

    })
  },

  /** 
   * 上拉加载更多
  */
  loadMore() {
    console.log('加载更多')
    if (this.data.flag) {
      this.orderList()

    }


  }

})